home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_libxml.idb / usr / freeware / include / gnome-xml / parser.h.z / parser.h
Encoding:
C/C++ Source or Header  |  1999-07-16  |  9.0 KB  |  246 lines

  1. /*
  2.  * parser.h : constants and stuff related to the XML parser.
  3.  *
  4.  * See Copyright for the status of this software.
  5.  *
  6.  * Daniel.Veillard@w3.org
  7.  */
  8.  
  9. #ifndef __XML_PARSER_H__
  10. #define __XML_PARSER_H__
  11.  
  12. #include "tree.h"
  13. #include "xmlIO.h"
  14.  
  15. #ifdef __cplusplus
  16. extern "C" {
  17. #endif
  18.  
  19. /*
  20.  * Constants.
  21.  */
  22. #define XML_DEFAULT_VERSION    "1.0"
  23.  
  24. typedef void (* xmlParserInputDeallocate)(CHAR *);
  25. typedef struct xmlParserInput {
  26.     /* Input buffer */
  27.     xmlParserInputBufferPtr buf;      /* UTF-8 encoded buffer */
  28.  
  29.     const char *filename;             /* The file analyzed, if any */
  30.     const CHAR *base;                 /* Base of the array to parse */
  31.     const CHAR *cur;                  /* Current char being parsed */
  32.     int line;                         /* Current line */
  33.     int col;                          /* Current column */
  34.     xmlParserInputDeallocate free;    /* function to deallocate the base */
  35. } xmlParserInput;
  36. typedef xmlParserInput *xmlParserInputPtr;
  37.  
  38. typedef struct _xmlParserNodeInfo {
  39.   const struct xmlNode* node;
  40.   /* Position & line # that text that created the node begins & ends on */
  41.   unsigned long begin_pos;
  42.   unsigned long begin_line;
  43.   unsigned long end_pos;
  44.   unsigned long end_line;
  45. } _xmlParserNodeInfo;
  46. typedef _xmlParserNodeInfo xmlParserNodeInfo;
  47.  
  48. typedef struct xmlParserNodeInfoSeq {
  49.   unsigned long maximum;
  50.   unsigned long length;
  51.   xmlParserNodeInfo* buffer;
  52. } _xmlParserNodeInfoSeq;
  53. typedef _xmlParserNodeInfoSeq xmlParserNodeInfoSeq;
  54. typedef xmlParserNodeInfoSeq *xmlParserNodeInfoSeqPtr;
  55.  
  56. typedef struct _xmlParserCtxt {
  57.     struct xmlSAXHandler *sax;        /* The SAX handler */
  58.     void            *userData;        /* the document being built */
  59.     xmlDocPtr           myDoc;        /* the document being built */
  60.     int            wellFormed;        /* is the document well formed */
  61.     int       replaceEntities;        /* shall we replace entities ? */
  62.     const CHAR     *version;          /* the XML version string */
  63.     const CHAR     *encoding;         /* encoding, if any */
  64.     int             standalone;       /* standalone document */
  65.  
  66.     /* Input stream stack */
  67.     xmlParserInputPtr  input;         /* Current input stream */
  68.     int                inputNr;       /* Number of current input streams */
  69.     int                inputMax;      /* Max number of input streams */
  70.     xmlParserInputPtr *inputTab;      /* stack of inputs */
  71.  
  72.     /* Node analysis stack */
  73.     xmlNodePtr         node;          /* Current parsed Node */
  74.     int                nodeNr;        /* Depth of the parsing stack */
  75.     int                nodeMax;       /* Max depth of the parsing stack */
  76.     xmlNodePtr        *nodeTab;       /* array of nodes */
  77.  
  78.     int record_info;                  /* Whether node info should be kept */
  79.     xmlParserNodeInfoSeq node_seq;    /* info about each node parsed */
  80. } _xmlParserCtxt;
  81. typedef _xmlParserCtxt xmlParserCtxt;
  82. typedef xmlParserCtxt *xmlParserCtxtPtr;
  83.  
  84. /*
  85.  * a SAX Locator.
  86.  */
  87.  
  88. typedef struct xmlSAXLocator {
  89.     const CHAR *(*getPublicId)(void *ctx);
  90.     const CHAR *(*getSystemId)(void *ctx);
  91.     int (*getLineNumber)(void *ctx);
  92.     int (*getColumnNumber)(void *ctx);
  93. } _xmlSAXLocator;
  94. typedef _xmlSAXLocator xmlSAXLocator;
  95. typedef xmlSAXLocator *xmlSAXLocatorPtr;
  96.  
  97. /*
  98.  * a SAX Exception.
  99.  */
  100.  
  101. #include "entities.h"
  102.  
  103. typedef xmlParserInputPtr (*resolveEntitySAXFunc) (void *ctx,
  104.                 const CHAR *publicId, const CHAR *systemId);
  105. typedef void (*internalSubsetSAXFunc) (void *ctx, const CHAR *name,
  106.                             const CHAR *ExternalID, const CHAR *SystemID);
  107. typedef xmlEntityPtr (*getEntitySAXFunc) (void *ctx,
  108.                             const CHAR *name);
  109. typedef void (*entityDeclSAXFunc) (void *ctx,
  110.                             const CHAR *name, int type, const CHAR *publicId,
  111.                 const CHAR *systemId, CHAR *content);
  112. typedef void (*notationDeclSAXFunc)(void *ctx, const CHAR *name,
  113.                 const CHAR *publicId, const CHAR *systemId);
  114. typedef void (*attributeDeclSAXFunc)(void *ctx, const CHAR *elem,
  115.                             const CHAR *name, int type, int def,
  116.                 const CHAR *defaultValue, xmlEnumerationPtr tree);
  117. typedef void (*elementDeclSAXFunc)(void *ctx, const CHAR *name,
  118.                 int type, xmlElementContentPtr content);
  119. typedef void (*unparsedEntityDeclSAXFunc)(void *ctx,
  120.                             const CHAR *name, const CHAR *publicId,
  121.                 const CHAR *systemId, const CHAR *notationName);
  122. typedef void (*setDocumentLocatorSAXFunc) (void *ctx,
  123.                             xmlSAXLocatorPtr loc);
  124. typedef void (*startDocumentSAXFunc) (void *ctx);
  125. typedef void (*endDocumentSAXFunc) (void *ctx);
  126. typedef void (*startElementSAXFunc) (void *ctx, const CHAR *name,
  127.                             const CHAR **atts);
  128. typedef void (*endElementSAXFunc) (void *ctx, const CHAR *name);
  129. typedef void (*attributeSAXFunc) (void *ctx, const CHAR *name,
  130.                                   const CHAR *value);
  131. typedef void (*referenceSAXFunc) (void *ctx, const CHAR *name);
  132. typedef void (*charactersSAXFunc) (void *ctx, const CHAR *ch,
  133.                     int len);
  134. typedef void (*ignorableWhitespaceSAXFunc) (void *ctx,
  135.                 const CHAR *ch, int len);
  136. typedef void (*processingInstructionSAXFunc) (void *ctx,
  137.                             const CHAR *target, const CHAR *data);
  138. typedef void (*commentSAXFunc) (void *ctx, const CHAR *value);
  139. typedef void (*warningSAXFunc) (void *ctx, const char *msg, ...);
  140. typedef void (*errorSAXFunc) (void *ctx, const char *msg, ...);
  141. typedef void (*fatalErrorSAXFunc) (void *ctx, const char *msg, ...);
  142. typedef int (*isStandaloneSAXFunc) (void *ctx);
  143. typedef int (*hasInternalSubsetSAXFunc) (void *ctx);
  144. typedef int (*hasExternalSubsetSAXFunc) (void *ctx);
  145.  
  146. typedef struct xmlSAXHandler {
  147.     internalSubsetSAXFunc internalSubset;
  148.     isStandaloneSAXFunc isStandalone;
  149.     hasInternalSubsetSAXFunc hasInternalSubset;
  150.     hasExternalSubsetSAXFunc hasExternalSubset;
  151.     resolveEntitySAXFunc resolveEntity;
  152.     getEntitySAXFunc getEntity;
  153.     entityDeclSAXFunc entityDecl;
  154.     notationDeclSAXFunc notationDecl;
  155.     attributeDeclSAXFunc attributeDecl;
  156.     elementDeclSAXFunc elementDecl;
  157.     unparsedEntityDeclSAXFunc unparsedEntityDecl;
  158.     setDocumentLocatorSAXFunc setDocumentLocator;
  159.     startDocumentSAXFunc startDocument;
  160.     endDocumentSAXFunc endDocument;
  161.     startElementSAXFunc startElement;
  162.     endElementSAXFunc endElement;
  163.     referenceSAXFunc reference;
  164.     charactersSAXFunc characters;
  165.     ignorableWhitespaceSAXFunc ignorableWhitespace;
  166.     processingInstructionSAXFunc processingInstruction;
  167.     commentSAXFunc comment;
  168.     warningSAXFunc warning;
  169.     errorSAXFunc error;
  170.     fatalErrorSAXFunc fatalError;
  171. } xmlSAXHandler;
  172. typedef xmlSAXHandler *xmlSAXHandlerPtr;
  173.  
  174. /*
  175.  * Global variables: just the SAX interface tables we are looking for full
  176.  *      reentrancy of the code and version infos.
  177.  */
  178. extern const char *xmlParserVersion;
  179.  
  180. extern xmlSAXLocator xmlDefaultSAXLocator;
  181. extern xmlSAXHandler xmlDefaultSAXHandler;
  182.  
  183. #include "entities.h"
  184. #include "xml-error.h"
  185.  
  186. /*
  187.  * CHAR handling
  188.  */
  189. CHAR *xmlStrdup(const CHAR *cur);
  190. CHAR *xmlStrndup(const CHAR *cur, int len);
  191. CHAR *xmlStrchr(const CHAR *str, CHAR val);
  192. int xmlStrcmp(const CHAR *str1, const CHAR *str2);
  193. int xmlStrncmp(const CHAR *str1, const CHAR *str2, int len);
  194. int xmlStrlen(const CHAR *str);
  195. CHAR *xmlStrcat(CHAR *cur, const CHAR *add);
  196. CHAR *xmlStrncat(CHAR *cur, const CHAR *add, int len);
  197.  
  198. /*
  199.  * Interfaces
  200.  */
  201. xmlDocPtr xmlParseDoc(CHAR *cur);
  202. xmlDocPtr xmlParseMemory(char *buffer, int size);
  203. xmlDocPtr xmlParseFile(const char *filename);
  204. int xmlSubstituteEntitiesDefault(int val);
  205.  
  206. /*
  207.  * Recovery mode 
  208.  */
  209. xmlDocPtr xmlRecoverDoc(CHAR *cur);
  210. xmlDocPtr xmlRecoverMemory(char *buffer, int size);
  211. xmlDocPtr xmlRecoverFile(const char *filename);
  212.  
  213. /*
  214.  * Internal routines
  215.  */
  216. int xmlParseDocument(xmlParserCtxtPtr ctxt);
  217. xmlDocPtr xmlSAXParseDoc(xmlSAXHandlerPtr sax, CHAR *cur, int recovery);
  218. xmlDocPtr xmlSAXParseMemory(xmlSAXHandlerPtr sax, char *buffer,
  219.                                    int size, int recovery);
  220. xmlDocPtr xmlSAXParseFile(xmlSAXHandlerPtr sax, const char *filename,
  221.                                  int recovery);
  222. xmlDtdPtr xmlParseDTD(const CHAR *ExternalID, const CHAR *SystemID);
  223. xmlDtdPtr xmlSAXParseDTD(xmlSAXHandlerPtr sax, const CHAR *ExternalID,
  224.                          const CHAR *SystemID);
  225. void xmlInitParserCtxt(xmlParserCtxtPtr ctxt);
  226. void xmlClearParserCtxt(xmlParserCtxtPtr ctxt);
  227. void xmlSetupParserForBuffer(xmlParserCtxtPtr ctxt, const CHAR* buffer,
  228.                                     const char* filename);
  229.  
  230. const xmlParserNodeInfo* xmlParserFindNodeInfo(const xmlParserCtxt* ctxt,
  231.                                                const xmlNode* node);
  232. void xmlInitNodeInfoSeq(xmlParserNodeInfoSeqPtr seq);
  233. void xmlClearNodeInfoSeq(xmlParserNodeInfoSeqPtr seq);
  234. unsigned long xmlParserFindNodeInfoIndex(const xmlParserNodeInfoSeq* seq,
  235.                                          const xmlNode* node);
  236. void xmlParserAddNodeInfo(xmlParserCtxtPtr ctxt,
  237.                           const xmlParserNodeInfo* info);
  238.  
  239. void xmlDefaultSAXHandlerInit(void);
  240. #ifdef __cplusplus
  241. }
  242. #endif
  243.  
  244. #endif /* __XML_PARSER_H__ */
  245.  
  246.